package com.lucien.test;

import java.sql.*;

public class ContentJDBC {
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;

        String Driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/user?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF8&useSSL=false";
        String username = "root";
        String password = "799774821";
        String sql = "select name,password,age from userinfo";
        try {
            Class.forName(Driver);
            con = DriverManager.getConnection(url,username,password);
            stmt = con.prepareStatement(sql);
            rs = stmt.executeQuery();

            while(rs.next()) {
                System.out.println("name:"+rs.getString("name")+",password:"+rs.getString("password")+",age:"+rs.getInt("age"));
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
                try {
                    if (rs!=null) rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                try {
                    if (stmt!=null) stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                try {
                    if (con!=null) con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }


        }
    }
}
